package com.aiphoto.upload.controller;

import com.aiphoto.upload.dao.AiMonitoringDao;
import com.aiphoto.upload.entity.AiMonitoring;
import com.aiphoto.upload.service.AiMonitoringService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.tomcat.util.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Api(description = "Ai监控接口")
@RestController
@RequestMapping("AiMonitoring")
@CrossOrigin
public class AiMonitoringController {
    @Autowired
    private AiMonitoringDao aiMonitoringService;

    @Scheduled(cron = "0/5 * * * * ? ")
    public void InsertAiMonitoring(){
        UploadController uploadController = new UploadController();
        System.out.println("开始执行");
        Map map =uploadController.upload();
        if(map.size()>0){
            int i =aiMonitoringService.InsertAiMonitoring(map);
            if (i==1){
                System.out.println("数据上传服务器成功!");
                System.out.println("开始删除本地文本");
                String fileName = "C:\\FIS\\v6.500\\path_next.txt";
                File file = new File(fileName);
                // 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
                if (file.exists() && file.isFile()) {
                    if (file.delete()) {
                        System.out.println("删除文件" + fileName + "成功！");

                    } else {
                        System.out.println("删除文件" + fileName + "失败！");

                    }
                } else {
                    System.out.println("删除文件失败：" + fileName + "不存在！");

                }
            }
            }else {
            System.out.println("没有数据!");
        }
        System.out.println("执行结束!");
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>");
    }


}
